<template>
    <div class="container">
      <el-cascader
        v-model="orgPath1"
        :options="organizationOptions"
        :props="cascaderProps"
        placeholder="请选择组织机构"
        filterable
        clearable
        style="width: 340px"
        @change="handleChange"
    />
        <el-select v-model="value1" placeholder="角色" style="width: 240px;margin-left: 2rem">
            <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value1"
            :disabled="item.disabled"
        />
        </el-select>

        <el-input v-model="input" style="width: 240px;margin-left: 2rem" placeholder="输入角色名称" />
        <el-button style="width: 6rem;margin-left: 2rem;background-color: rgba(110, 78, 208, 0.1); border-color: #6f42c1; color: rgb(110, 78, 208);" type="primary" @click="filterUser">查询</el-button>
        <el-button style="width: 6rem;background-color: rgba(110, 78, 208, 0.1); border-color: #6f42c1; color: rgb(110, 78, 208);" type="primary" @click="newUser" v-if="hasPermission(authStore.permissions,34)">新建用户</el-button>
        <!-- 点击新建角色打开 -->
        <el-dialog v-model="visible" :show-close="false" width="800">
      <template #header="{ close, titleId, titleClass }">
        <div class="my-header">
          <div>新建/修改用户</div>
          <el-button type="danger" @click="close">
            <el-icon class="el-icon"><CircleCloseFilled /></el-icon>
          </el-button>
        </div>
      </template>

      <!-- 输入框区域 -->
      <div style="display: flex;">
        <div class="input-text">
          <span style="color: red;">*</span>所属机构:
        </div>
        <el-cascader
          v-model="orgPath"
          :options="organizationOptions"
          :props="cascaderProps"
          placeholder="请选择组织机构"
          filterable
          clearable
          style="width: 240px"
          ref="cascaderRef"
          @change="handleChange"
        />
      </div>
        <p v-if="errors.organization" class="error-text">请选择所属机构</p>

      <div style="display: flex;margin-top: 1rem">
        <div class="input-text">
          <span style="color: red;">*</span>用户名:
        </div>
        <el-input style="width: 240px" v-model="userName" @input="validateUsername" placeholder="用户名只能包含字母和数字"></el-input>
    </div>
      <p v-if="errors.username" class="error-text">用户名只能包含英文字母</p>

      <div style="display: flex;margin-top: 1rem">
        <div class="input-text">
          <span style="color: red;">*</span>角色:
        </div>
        <el-select v-model="value1" placeholder="选择角色" style="width: 240px">
            <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value1"
            :disabled="item.disabled"
        />
        </el-select>
    
      </div>
      <p v-if="errors.role" class="error-text">请选择角色</p>

    <div style="display: flex;margin-top: 1rem">
        <div class="input-text">
          <span style="color: red;">*</span>姓名:
        </div>
        <el-input style="width: 240px" v-model="Name" ></el-input>
    </div>
    <p v-if="errors.name" class="error-text">请输入姓名</p>

        <div style="display: flex;margin-top: 1rem">
        <div class="input-text">
          <span style="color: red;"></span>手机号:
        </div>
        <el-input style="width: 240px" v-model="Number1" ></el-input>
        </div>

        <div style="display: flex;margin-top: 1rem">
        <div class="input-text">
          <span style="color: red;"></span>关联DJI账号:
        </div>
        <el-select v-model="DJid" placeholder="选择关联的DJI账号" style="width: 240px">
            <el-option
            v-for="item in allDjiList"
            :label="item.username"
            :value="item.id"
        />
        </el-select>
    
      </div>
        <div style="display: flex;margin-top: 1rem">
        <div class="input-text">
        <span style="color: transparent;">*</span>
          备注：
        </div>
        <el-input style="width: 240px" v-model="userMessage"></el-input>
        </div>
      <!-- 保存和取消按钮 -->
      <div style="margin-top: 2rem;position: relative;height: 3rem;">
        <div style="position: absolute;right: 0;">
          <el-button @click="visible = false">取消</el-button>
          <el-button type="primary" @click="sumbitMessage()">保存</el-button>
        </div>
      </div>
    </el-dialog>


    <el-table :data="displayedData" style="width: 95%; margin-top: 3rem;"  class="auto-width-table">
  <el-table-column label="序号" >
    <template #default="{ row, $index }">
      <span v-if="row.role && row.user.status == 'S'">{{ (currentPage - 1) * pageSize + $index + 1 }}</span>
      <span v-else-if="row.role && row.user.status == 'F'" style="color: gray;">{{ (currentPage - 1) * pageSize + $index + 1 }}</span>
    </template>
  </el-table-column>

  <el-table-column prop="role.roleName" label="用户名" >
    <template #default="{ row }">
      <span v-if="row.role && row.user.status == 'S'" style="color: black;">{{ row.user.username }}</span>
      <span v-else-if="row.role && row.user.status == 'F'" style="color: gray;">{{ row.user.username }}</span>
      <span v-else style="color: transparent;">空</span>
    </template>
  </el-table-column>
  
  <el-table-column prop="role.roleName" label="角色" >
    <template #default="{ row }">
      <span v-if="row.role&& row.user.status == 'S'" style="color: black;">{{ row.role.roleName }}</span>
      <span v-else-if="row.role&& row.user.status == 'F'" style="color: gray;">{{ row.role.roleName }}</span>
      <span v-else style="color: transparent;">空</span>
    </template>
  </el-table-column>

  <el-table-column prop="role.roleName" label="姓名" >
    <template #default="{ row }">
      <span v-if="row.role&& row.user.status == 'S'" style="color: black;">{{ row.user.name }}</span>
      <span v-else-if="row.role&& row.user.status == 'F'" style="color: gray;">{{ row.user.name }}</span>
      <span v-else style="color: transparent;">空</span>
    </template>
  </el-table-column>

  <el-table-column prop="role.roleName" label="关联的DJI账号">
    <template #default="{ row }">
      <span v-if="row.role&& row.user.status == 'S'" style="color: black;">{{ row.djiUser?.username }}</span>
      <span v-else-if="row.role&& row.user.status == 'F'" style="color: gray;">{{ row.djiUser?.username }}</span>
      <span v-else style="color: transparent;">空</span>
    </template>
  </el-table-column>
  
  <el-table-column label="所属机构">
  <template #default="{ row }">
    <!-- 超级管理员 -->
    <template v-if="row?.role?.roleName == '超级管理员'">
      <span :style="{ color: row.user.status === 'F' ? 'gray' : 'black' }">
        中国铁塔股份有限公司安徽省分公司
      </span>
    </template>

    <!-- 普通用户 -->
    <template v-else-if="row?.role && row?.role?.roleName != '超级管理员'">
      <span :style="{ color: row.user.status === 'F' ? 'gray' : 'black' }">
        {{ row.organizationName || '暂未分配组织' }}
      </span>
    </template>

    <!-- 无角色信息 -->
    <template v-else>
      <span style="color: transparent;">空</span>
    </template>
  </template>
</el-table-column>

  
  <el-table-column prop="role.createTime" label="创建时间" >
    <template #default="{ row }">
      <span v-if="row.role&& row.user.status == 'S'" style="color: black;">{{ row.user.createTime }}</span>
      <span v-else-if="row.role&& row.user.status == 'F'" style="color: gray;">{{ row.user.createTime }}</span>
      <span v-else style="color: transparent;">空</span>
    </template>
  </el-table-column>
  
  <el-table-column fixed="right" label="操作" >
    <template #default="{ row }">
      <!-- @click="reChange(row.user.id)" -->
      <div v-if="row.role && row.user.status == 'S'&& row.role.roleName != '超级管理员'&&row.user.username !== 'ruiboAdmin'  ">
        <el-button link type="primary" size="small" @click="reChange(row)" v-if="hasPermission(authStore.permissions,35)" style="color: rgb(110, 78, 208);">重置密码</el-button>
        <el-button link type="primary" size="small" @click="changeRole(row)" v-if="hasPermission(authStore.permissions,36)" style="color: rgb(110, 78, 208);">修改</el-button>
        <el-button link type="primary" size="small" @click="banItem(row,0)" v-if="hasPermission(authStore.permissions,37)" style="color: rgb(110, 78, 208);">禁用</el-button>
        <el-button link type="primary" size="small" @click="deleteItem(row)" v-if="hasPermission(authStore.permissions,38)" style="color:#f56c6c;">删除</el-button>
      </div>
      <div v-else-if="row.role && row.user.status == 'F' && row.role.roleName != '超级管理员'&&row.user.username !== 'ruiboAdmin'">
        <el-button link type="primary" size="small" @click="deleteItem(row)" v-if="hasPermission(authStore.permissions,38)" style="color: rgb(110, 78, 208);">删除</el-button>
        <el-button link type="primary" size="small" @click="banItem(row,1)" v-if="hasPermission(authStore.permissions,37)" style="color:#f56c6c;">恢复</el-button>
      </div>
      <div v-else style="color: transparent;">无操作</div>
    </template>
  </el-table-column>
</el-table>
<!-- 这里写分页页面 -->

<el-pagination
  style="margin-top:2rem;"
  v-model:current-page="currentPage"
  v-model:page-size="pageSize"
  :total="total"
  layout="prev, pager, next, jumper"
  :background="true"
  @current-change="handleCurrentChange"
/>

    </div>
<!-- 提示框重置密码 -->
 <el-dialog v-model="reChangVisible" title="提示" width="500" center>
            <span>
              是否需要重置用户 "{{reChangeItem.user.username}} 的密码"
            </span>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="reChangVisible = false">取消</el-button>
              <el-button type="primary" @click="reChangePassword()">
               确认重置
            </el-button>
          </div>
        </template>
      </el-dialog>
 <!-- 禁用恢复提示的提示框 -->
 <el-dialog v-model="banVisible" title="提示" width="500" center>
            <span>
              是否禁用/恢复用户 "{{banMessage.user.username}}"
            </span>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="banVisible = false">取消</el-button>
              <el-button type="primary" @click="banUser()">
               确认
            </el-button>
          </div>
        </template>
      </el-dialog>
       <!-- 删除提示的提示框 -->
       <el-dialog v-model="DeleteVisible" title="提示" width="500" center>
            <span>
              是否需要删除用户 "{{deleteOne.user.username}}"
            </span>
          <template #footer>
            <div class="dialog-footer">
              <el-button @click="DeleteVisible = false">取消</el-button>
              <el-button type="primary" @click="handleClick()">
               确认删除
            </el-button>
          </div>
        </template>
      </el-dialog>


</template>

<script lang="ts" setup>
    import { CircleCloseFilled } from '@element-plus/icons-vue';
    import { ref ,onMounted , nextTick ,onUnmounted } from 'vue'
    import request from '@/utils/request';
    import  { ElMessage , ElCascader} from 'element-plus'; // 引入 el-tree 的类型

    import type { TreeInstance } from 'element-plus'; // 引入 el-tree 的类型
    import { useAuthStore } from '@/stores/user';
    const authStore = useAuthStore();//使用store仓库进行数据管理
    import { hasPermission } from '@/utils/permissionUtils';
    import showMessage from '@/utils/showMessage'

    const errors = ref({
      organization: false,
      username: false,
      name: false,
      phone: false,
      role: false,
      dji: false
    });


    const selectedID= ref<any>()

    const value = ref('')
    const options = <any>ref([])   //全部组织     

    const value1 = ref('')
    const options1 = ref<any>([]);  //全部角色 

    const value2 = ref('')
    const options2 = <any>ref([])   //大疆   
    const Name = ref();//姓名
    const Number1 = ref<any>();//手机号
    const tableData = ref([]); // 原始数据
    const displayedData = ref([]); // 当前页显示的数据
    const currentPage = ref(1); // 当前页码
    const pageSize = ref(10); // 每页条数
    const total = ref(0); // 总条数
    const input = ref('')
    const userName = ref('')
    const userMessage = ref('')
    const visible = ref(false)
    const DJid = ref<any>()
    const flag = ref()//flag为1代表是新建，为2表示是修改

    const orgPath = ref<number[]>([]); // 用于原始路径绑定
      const orgPath1 = ref<number[]>([]); // 用于原始路径绑定
    const selectedValue = ref<string>(''); // 最终展示用的值

const organizationOptions = ref<any[]>([]);


const validateUsername = (value:any) => {
  // 过滤非英文字符
  userName.value = value.replace(/[^a-zA-Z0-9]/g, '');
  
  // 校验是否为空
  errors.value.username = userName.value.length === 0;
};

// 配置：emitPath: true 让我们拿到路径数组
const cascaderProps = {
  emitPath: true,
  checkStrictly: true
};

// 处理选择结果
const cascaderRef = ref<InstanceType<typeof ElCascader>>();
const handleChange = (value:any) => {
  if (value.length === 1) {
    selectedValue.value = `${value[0]}` ; // 二级组织
  } else if (value.length === 2) {
    selectedValue.value = `${value[0]}-${value[1]}`; // 二级ID-三级ID
  }

  if (cascaderRef.value) {
    
        cascaderRef.value?.togglePopperVisible(false);
      }
};


// 请求并构建二级+三级组织数据
const getOrganizationOptions = () => {  
  request.get('/user/getAllSecondaryOrganization').then((res1) => {
    const secondList = res1.data;
    request.get('/user/getAllThirdOrganization').then((res2) => {
      const thirdList = res2.data;
      console.log(121212,res2)
      const grouped = thirdList.reduce((acc: any, cur: any) => {
        if (!acc[cur.secondaryID]) acc[cur.secondaryID] = [];
        acc[cur.secondaryID].push({
          label: cur.organizationName,
          value: cur.id
        });
        return acc;
      }, {});

      const secondLevel = secondList.map((item: any) => ({
        label: item.organizationName,
        value: item.id,
        children: grouped[item.id] || []
      }));

      organizationOptions.value = secondLevel;
    });
  });
};


    // 添加响应式检测函数
    const detectPageSize = () => {
    const width = window.innerWidth;
    pageSize.value = width <= 1800 ? 10 : 20; // ≤1200px 时显示10条，>1200px 时显示20条
    updateDisplayedData();
  };

    // 新建角色
    const newUser= () => {
       errors.value = {
      organization: false,
      username: false,
      name: false,
      phone: false,
      role: false,
      dji: false
    };
      orgPath.value = []
      value1.value = ''
      Name.value = ''
      DJid.value = 
      Number1.value = ''
      visible.value = true;
      flag.value = 1
      userName.value = ''
      userMessage.value = ''
      alarmTree.value = null
      inspectionTree.value = null
      resourceTree.value = null
      systemTree.value = null
    }

    const filterUser = () => {
        
          request.post("/user/getConditionUser" ,{
            organizationID:selectedValue.value || '',
            roleID:value1.value || '',
            username:input.value || '',
          }).then(
            (res)=>{
              if(res.status == 200){
                displayedData.value = res.data
            }
            }
          )
    }
    // 删除逻辑

    const DeleteVisible = ref(false)
    const deleteOne = ref()
    const deleteItem   =  (row:any) => {
      DeleteVisible.value = true 
      deleteOne.value = row
    } 
    
    const handleClick =() => {
        const formData = new FormData();
        formData.append("userID",deleteOne.value.user.id),
        request.post("/user/deleteUserByID",formData).then(
          (res)=>{
            showMessage(res);
            if(res.status == 200){
            //删除用户日志 
              request.post('/user/insertOperation',{
                username : authStore.user?.username,
                name : authStore.user?.name,
                organizationID:authStore.organizationID,
                ip:null,
                operationModel:"系统管理",
                operationResult:"删除用户成功",
                operationTime:null,
                operationType:"operation"
              }).then(res => {
              
              })
              // 获取所有用户信息
              getAllUser()

              DeleteVisible.value = false
            }
          }
        )
    }
    // 重置密码
    const reChangVisible = ref(false)
    const reChangeItem = ref()
    const reChange = (data:any) => {      
      reChangeItem.value = data
      reChangVisible.value = true
    }

    const reChangePassword = () => {
        const formData = new FormData();
        formData.append("userID",reChangeItem.value.user.id),
        request.post("/user/resizeUserPassword",formData).then(
          (res)=>{
             showMessage(res);
            if(res.status == 200){
              // 重置密码
              request.post('/user/insertOperation',{
                username : authStore.user?.username,
                name : authStore.user?.name,
                organizationID:authStore.organizationID,
                ip:null,
                operationModel:"系统管理",
                operationResult:"重置用户密码",
                operationTime:null,
                operationType:"operation"
              }).then(res => {
             
              })
              // 获取所有用户信息
              getAllUser()
              reChangVisible.value = false
            }
          }
        )
    }
    // 禁用用户
const banVisible = ref(false)
const banMessage = ref()
const flagOne = ref()
const banItem = (row:any,Flag:number) => {
  banVisible.value = true
  banMessage.value = row
  flagOne.value = Flag
}


    const banUser = () => {

      if(flagOne.value == 0){
        // 禁用
        const formData = new FormData();
        formData.append("userID",banMessage.value.user.id),
        request.post("/user/disableUser",formData).then(
          (res)=>{
            if(res.status == 200){
              showMessage(res);
              // 禁用用户
              request.post('/user/insertOperation',{
                username : authStore.user?.username,
                name : authStore.user?.name,
                organizationID:authStore.organizationID,
                ip:null,
                operationModel:"系统管理",
                operationResult:"禁用用户",
                operationTime:null,
                operationType:"operation"
              }).then(res => {
  
              })
              // 获取所有用户信息
              getAllUser()
              banVisible.value = false
            }
          }
        )
      }else if(flagOne.value == 1){
        // 恢复
        const formData = new FormData();
        formData.append("userID",banMessage.value.user.id),
        request.post("/user/unBlockUser",formData).then(
          (res)=>{
            showMessage(res);
            if(res.status == 200){
              // 禁用用户
              request.post('/user/insertOperation',{
                username : authStore.user?.username,
                name : authStore.user?.name,
                organizationID:authStore.organizationID,
                ip:null,
                operationModel:"系统管理",
                operationResult:"恢复用户",
                operationTime:null,
                operationType:"operation"
              }).then(res => {
            
              })
              // 获取所有用户信息
              getAllUser()
              banVisible.value = false
            }
          }
        )
      }
    }
    // 修改逻辑
    const changeUserItem = ref()
    const changeRole = (row: any) => {
      errors.value = {
      organization: false,
      username: false,
      name: false,
      phone: false,
      role: false,
      dji: false
    };
      
        changeUserItem.value = row
        selectedID.value = row.user.id
        userName.value = row.user.username;//用户名
        userMessage.value = row.user.description;//备注
        Name.value = row.user.name;//姓名
        Number1.value = row.user.phoneNumber; //手机号
        value1.value = row.role.id; //角色id
        DJid.value  = row.user.djiID || ''

        if (row.user.organizationID) {
          selectedValue.value = row.user.organizationID;
            const parts = (selectedValue.value.split('-') as string[]).map(str => Number(str.trim()));
        if (parts.length > 0) {
          orgPath.value = parts; // 让 el-cascader 回显
        }
      }
        
        // 提取权限数据
        visible.value = true;
        flag.value = 2;
};
// 引用树形组件
const alarmTree = ref<TreeInstance | null>(null);
const inspectionTree = ref<TreeInstance | null>(null);
const resourceTree = ref<TreeInstance | null>(null);
const systemTree = ref<TreeInstance | null>(null);
const sumbitMessage =() => {
  errors.value.organization = !orgPath.value.length;
  errors.value.username = !userName.value?.trim();
  errors.value.name = !Name.value?.trim();
  errors.value.role = !value1.value;

  const hasError = Object.values(errors.value).some(Boolean);
  if (hasError) return; // 有任何一个错误则阻止提交
  if(flag.value === 1) {
    const username = userName.value;//用户名
    const description = userMessage.value;//备注
    const name = Name.value;//姓名
    const phoneNumber = Number1.value; //手机号
    const organizationID : String = selectedValue.value; //组织的id
    const roleID = value1.value; //角色id
    const djiID = DJid.value
    
    request.post('/user/insertUser',{
        username,
        description,
        phoneNumber,
        organizationID,
        roleID,     
        djiID,
        name,
    }).then((res)=>{
      showMessage(res);
      if( res.data.status == 'success') {
        visible.value = false
        userName.value = '',
        userMessage.value = '',
        Name.value ='', 
        value.value = '',
        value1.value = '',
        Number1.value = ''

         // 新建用户
         request.post('/user/insertOperation',{
                username : authStore.user?.username,
                name : authStore.user?.name,
                organizationID:authStore.organizationID,
                ip:null,
                operationModel:"系统管理",
                operationResult:"用户新建成功",
                operationTime:null,
                operationType:"operation"
              }).then(res => {
       
              })

        getAllUser()
      } 
    })
  } else if (flag.value === 2 ) {
    const username = userName.value;//用户名
    const primaryUsername = changeUserItem.value.user.username
    const description = userMessage.value;//备注
    const name = Name.value;//姓名
    const phoneNumber = Number1.value; //手机号
    const organizationID = selectedValue.value; //组织的id
    const roleID = value1.value; //角色id
    const djiID = DJid.value
    const id = selectedID.value  
    request.post('/user/updateUser',{
        username,
        primaryUsername,
        description,
        phoneNumber,
        organizationID,
        roleID,
        djiID,
        name,
        id,
    }).then((res)=>{
      showMessage(res);
      if(res.status == 200) {
        visible.value = false
        userName.value = '',
        userMessage.value = '',
        Name.value ='', 
        value.value = '',
        value1.value = '',
        Number1.value = ''

         // 修改用户
         request.post('/user/insertOperation',{
                username : authStore.user?.username,
                name : authStore.user?.name,
                organizationID:authStore.organizationID,
                ip:null,
                operationModel:"系统管理",
                operationResult:"修改用户信息",
                operationTime:null,
                operationType:"operation"
              }).then(res => {
        
              })
        getAllUser()
      }
    })
  }
}

// 获取全部角色信息
const getAllRole = () => {
  request.get('/user/getAllRole').then(
    (res)=>{
      if(res.data){
       if(res.data){
        options1.value = res.data.map((item:any) =>({
            value1:item.role.id,
            label:item.role.roleName
        }))
       }
      }
    }
  )
}
// 获取全部DJI账号
const allDjiList = ref()
const getAllDJIUser = () =>{
  request.get('/resource/getAllDJIUser').then((res:any)=> {
    allDjiList.value = res.data
  })
}

// 获取全部三级组织信息
const getAllThirdOrganization = () => {
 
      // 获取三级菜单数据
      request.get('/user/getAllThirdOrganization').then((response) => {
       if (response.data) {        
        options.value = response.data.map((item:any) => ({
            value :item.id,
            label :item?.organizationName,
        }))        
       }
      })
    .catch((error) => {
      console.error('获取组织数据失败:', error);
    });
};


// 获取全部用户信息
const getAllUser = () => {
  request.get('/user/getAllUser').then(
    (res)=>{
      if(res.data){   
  
        tableData.value = res.data
        total.value = res.data.length;
        updateDisplayedData();
      }
    }
  )
}

// 更新显示的数据
const updateDisplayedData = () => {
  const start = (currentPage.value - 1) * pageSize.value;
  const end = start + pageSize.value;
  const currentData = tableData.value.slice(start, end);

  // 填充空行以确保表格显示10行
  displayedData.value = Array.from({ length: pageSize.value }, (_, index) => currentData[index] || {});
};

// 处理分页切换
const handleCurrentChange = (page: number) => { 
  currentPage.value = page;
  updateDisplayedData();
};

  onMounted(()=>{
    getOrganizationOptions();
    detectPageSize(); // 初始调用
    window.addEventListener('resize', detectPageSize);
    getAllDJIUser()
    getAllRole()
    getAllThirdOrganization()
    getAllUser()
  })
  onUnmounted(() => {
  window.removeEventListener('resize', detectPageSize);
});

</script>

<style scoped>
.container {
    width: 100%;
    height: calc(100vh - 120px);
    display: block;
    padding: 20px;
}
.container-head {
    display: flex
} 
.my-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 16px;
}
.input-text {
    width: 20%;
    height: 2rem;
    line-height: 2rem;
    margin-left: 1rem;
}
.input-text1 {
    width: 10%;
    height: 2rem;
    line-height: 2rem;
    margin-left: 1rem;
}
.selected-tab {
  background-color: #409eff;
  color: white;
}
.empty-row { 
  background-color: #f5f7fa;
  color: gray;
  text-align: center;
}


/* 表格自动宽度样式 */
.auto-width-table {
  table-layout: fixed; /* 关键属性 */
}

/* 定义各列宽度比例 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(1)) { width: 5%; }  /* 序号 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(2)) { width: 10%; } /* 任务名称 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(3)) { width: 10%; } /* 任务类型 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(4)) { width: 10%; } /* 通信塔类型 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(5)) { width: 10%; }  /* 地市 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(6)) { width: 13%; }  /* 区县 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(7)) { width: 17%; }  /* 巡视人员 */
.auto-width-table :deep(.el-table__header-wrapper th:nth-child(8)) { width: 25%; } /* 任务状态 */

/* 确保内容不溢出 */
.auto-width-table :deep(.cell) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .auto-width-table {
    min-width: 1000px; /* 在小屏幕上保持水平滚动 */
  }
}
.error-text {
  color: red;
  font-size: 12px;
  margin-left: 11rem;
  margin-top: 4px;
}
</style>